package com.Jhu1.service.impl;

import com.Jhu1.entity.User;
import com.Jhu1.mapper.UserMapper;
import com.Jhu1.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 用户�? 服务实现类
 * </p>
 *
 * @author 钟俊辉
 * @since 2025-01-14
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
        implements IUserService {
    @Autowired
    private UserMapper userMapper;


    @Override
    public User findByuserName(String userName) {
        return userMapper.findByuserName(userName);
    }

    @Override
    public void register(String userName, String password, String role) {
        password = SecurityUtil.getSecurityPassword(password);
        userMapper.register(userName, password, role);
    }

    @Override
    public void update(User user) {
        userMapper.update(user);
    }

    @Override
    public void updateAvatar(String url) {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("id");
        userMapper.updateAvatar(id, url);
    }

    @Override
    public void updatePwd(String newPwd) {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("id");
        userMapper.updatePwd(id, newPwd);
    }
}
